from aiogram import F
from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Back, Button, Cancel, Next
from aiogram_dialog.widgets.media import DynamicMedia

from poker_bot.core.models.enums.deposit import DepositStatus
from poker_bot.core.models.enums.withdraw import WithdrawStatus
from poker_bot.tg_bot.dialogs.extras import copy_start_data_to_ctx
from poker_bot.tg_bot.dialogs.getters.users import user_role_getter
from poker_bot.tg_bot.dialogs.getters.withdraws import withdraw_info_getter
from poker_bot.tg_bot.dialogs.widgets import LocaleText
from poker_bot.tg_bot.states import WithdrawDetailsSG

from .handlers import confirm_withdraw

withdraw_details_window = Window(
    LocaleText("withdraw-overview"),
    DynamicMedia(
        "invoice_screenshot", when=(F["user_is_admin"]) & (F["invoice_screenshot"])
    ),
    LocaleText("withdraw-id", wihtdraw_id="{withdraw_id}"),
    LocaleText("withdraw-status", status="{status_value}"),
    LocaleText("withdraw-summ", summ="{summ}"),
    LocaleText("withdraw-address", address="{address}"),
    LocaleText("payment-method", payment_method="{payment_method}"),
    LocaleText("user-username", username="{username}"),
    LocaleText("account-id", account_id="{account_id}"),
    LocaleText("was-created", was_created="{was_created}"),
    Next(
        LocaleText("confirm-deposit-payment-btn"),
        when=(F["user_is_admin"]) & (F["status"] == WithdrawStatus.on_moderation),
    ),
    Cancel(LocaleText("back-btn")),
    state=WithdrawDetailsSG.withdraw_details,
    getter=(withdraw_info_getter, user_role_getter),
)

confirm_withdraw_window = Window(
    LocaleText("confirm-withdraw-payment-msg"),
    Button(
        LocaleText("confirm-btn"),
        id="confirm_payment",
        on_click=confirm_withdraw,
    ),
    Back(LocaleText("back-btn")),
    state=WithdrawDetailsSG.confirm_withdraw,
)

withdraw_details_dialog = Dialog(
    withdraw_details_window,
    confirm_withdraw_window,
    on_start=copy_start_data_to_ctx,
)
